package Practice02;

import java.util.Scanner;

//计算平均数和总数
public class CalTotalAvg {
    public static void main(String[] args) {
        double[] scores = socres(4);
        System.out.println("总数是" + total(scores));
        System.out.println("平均数数:"+avg(scores));

    }

    //计算平均数
    public static double avg(double[] scores) {
        double avg = 0.0;
        avg = total(scores)/ (scores.length-2);

        return avg;
    }


    //计算总数
    public static double total(double[] scores) {
        double total = 0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i = 0; i < scores.length; i++) {
            if (max < scores[i]) {
                max = scores[i];
            }
            if (scores[i] < min) {
                min = scores[i];
            }
            total += scores[i];
        }
        return total - min - max;
    }


    //记录分数
    public static double[] socres(int sum) {
        Scanner scanner = new Scanner(System.in);
        double[] scores = new double[sum];
        for (int i = 0; i < sum; i++) {
            System.out.println("请输入第" + (i + 1) + "的分数");
            double score = scanner.nextDouble();
            scores[i] = score;
        }
        return scores;
    }


}
